<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8">
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.cookie.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.huifold.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/validate.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/utils.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/admin/add.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/page/admin/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <script src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/page/admin/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/style.css"/>

</head>
<body>
<div class="container">
    <div class="limitDiv">
        <span>充值金额</span>
        <input type="number" id="money" min="1" max="99999" placeholder="不多于6位数字" οninput="value=value.replace(/[^\d]/g,'')" autocomplete="off">

    </div>

    <div class="limitDiv">
        <button class="btn btn-primary radius"
                style="width: 44%;margin: 4% auto 2% auto;"
                id="add">
            确认
        </button>
    </div>

</div>
</body>
<script type="text/javascript">

    $("#add").click(function () {
        var money = $("#money").val();

        if (""==money) {
            layer.msg('充值金额不能为空', {icon: 2, time: 2000})
        } else {
            $.ajax({
                url: "${pageContext.request.contextPath}/PersonalCenter/chongzhi",
                data: {
                    "money": money
                },
                async : false,
                type: "get",
                contentType: "application/json;charset=UTF-8",
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        parent.layer.msg('充值成功', {icon: 1, time: 2000})

                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        window.parent.location.reload()//刷新父页面
                    } else {
                        layer.msg('充值失败', {icon: 2, time: 2000})
                    }
                },
                error: function () {
                    layer.msg('错误', {icon: 2, time: 2000})
                }
            })
        }


    })

</script>
</html>
